use std::sync::Arc;

use anyhow::Result;
use sea_orm::{DatabaseConnection, EntityTrait};

use crate::entity::pointpointgroup;
use crate::entity::prelude::Pointpointgroup;
use crate::repo::point_repo::DbContextHolder;

pub struct PointRltPointGroupRepo {
    db_contexts: Arc<Vec<DatabaseConnection>>,
}

impl DbContextHolder for PointRltPointGroupRepo {
    fn get_db_contexts(&self) -> &Vec<DatabaseConnection> {
        &self.db_contexts
    }
}

impl PointRltPointGroupRepo {
    pub fn new(dbs: Arc<Vec<DatabaseConnection>>) -> Self {
        Self { db_contexts: dbs }
    }
    // 根据 point_group_id 和 point_ids  删除
    pub async fn delete_point_rlt_point_group_by_point_group_id_and_point_ids_async(&self, machine_index: u32, point_group_id: i32, point_ids: Vec<i32>) -> Result<()> {
        let db_context = self.get_db_context(machine_index);
        // pointpointgroup::Entity::delete_many()
        //     .filter(pointpointgroup::Column::PointGroupsId.eq(point_group_id))
        //     .filter(pointpointgroup::Column::PointsId.eq_any(point_ids))
        //     .exec(db_context).await?;
        Ok(())
    }
    // // 根据 point_group_id 和 point_ids  添加
    // pub async fn add_point_rlt_point_group_by_point_group_id_and_point_ids_async(&self, machine_index: u32, point_group_id: i32, point_ids: Vec<i32>) -> Result<()> {
    //     let db_context = self.get_db_context(machine_index);
    //     let mut point_point_group = pointpointgroup::ActiveModel {
    //         point_groups_id: point_group_id,
    //         points_id: point_ids[0],
    //     };
    //     for i in 1..point_ids.len() {
    //         point_point_group = point_point_group.or_insert(pointpointgroup::ActiveModel {
    //             point_groups_id: point_group_id,
    //             points_id: point_ids[i],
    //         });
    //     }
    //     point_point_group.save(db_context).await?;
    //     Ok(())
    // }

}
